<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="name" label="知识名称">
      </el-table-column>
      <el-table-column prop="author" label="作者"> </el-table-column>
      <el-table-column prop="eduId" label="思政元素">
        <template slot-scope="scope">
          <span v-if="scope.row.eduId">
            {{ scope.row.sysIdeologicalEducation.name }}
          </span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleFiles(row)">
              查看资源
            </el-button>
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>

<script>
import {
  sysKnowledgeQuery,
  sysKnowledgeDelete,
} from "@/api/admin/courseLibrary/sysKnowledge.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        courseId: this.$store.getters.courseId,
      },
      tableData: [],
      pageObj: {},
    };
  },
  mounted() {
    this.getList();
    Bus.$on("refreshChapterKnowledgeList", (v) => {
      if (v) {
        Object.assign(this.listQuery, v);
      }
      this.getList();
    });
  },
  beforeDestroy() {
    Bus.$off("refreshChapterKnowledgeList");
  },
  methods: {
    getList() {
      sysKnowledgeQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data;
        this.pageObj = res.data;
      });
    },
    //附件管理
    handleFiles(row) {
      this.$store.commit("SETKNOLEDGE", row);
      this.$router.push({ name: "knowledge-files" });
    },
    //编辑
    handleEdit(row) {
      Bus.$emit("showDialogKnowledgeAdd", row);
    },
    //删除确认
    handleDelete(row) {
      this.$confirm("确定要删除吗?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.delete(row);
        })
        .catch(() => {});
    },
    //删除
    delete(row) {
      sysKnowledgeDelete(row.id).then((res) => {
        this.getList();
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
  },
};
</script>